#include "startwidget.h"
#include <QPixmap>
#include <QPalette>
#include <QFont>
startwidget::startwidget(QWidget *parent)  : QWidget(parent){
    setupUI();
    setupConnections();
}
startwidget::~startwidget()
{
}

void startwidget::setupUI()
{

    setFixedSize(1004, 1024);


    backgroundLabel = new QLabel(this);
    QPixmap background(":/bg2.jpg");
    backgroundLabel->setPixmap(background.scaled(size(), Qt::KeepAspectRatioByExpanding));
    backgroundLabel->setGeometry(0, 0, width(), height());


    startButton = new QPushButton("开始游戏", this);
    startButton->setFixedSize(400, 100);
    startButton->setFont(QFont("Microsoft YaHei", 60));
    startButton->setStyleSheet(
        "QPushButton {"
        "    background-color: #FFC0CB;"
        "    color: white;"
        "    border: none;"
        "    border-radius: 50px;"
        "    font-weight: bold;"
        "    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);"
        "    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);"
        "}"
        "QPushButton:hover {"
        "    background-color: #FFB6C1;"
        "    transform: translateY(-2px);"
        "}"
        "QPushButton:pressed {"
        "    background-color: #FFA07A;"
        "    transform: translateY(1px);"
        "}"
        );


    closeButton = new QPushButton("退出游戏", this);
    closeButton->setFixedSize(400, 100);
    closeButton->setFont(QFont("Microsoft YaHei", 60));
    closeButton->setStyleSheet(
        "QPushButton {"
        "    background-color: #FF9999;"
        "    color: white;"
        "    border: none;"
        "    border-radius: 30px;"
        "    font-weight: bold;"
        "    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);"
        "    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);"
        "}"
        "QPushButton:hover {"
        "    background-color: #FF6666;"
        "    transform: translateY(-2px);"
        "}"
        "QPushButton:pressed {"
        "    background-color: #FF4444;"
        "    transform: translateY(1px);"
        "}"
        );


    QVBoxLayout *mainLayout = new QVBoxLayout(this);
    mainLayout->addStretch();


    QHBoxLayout *buttonLayout = new QHBoxLayout();
    buttonLayout->addStretch();
    buttonLayout->addWidget(startButton);
    buttonLayout->addStretch();

    mainLayout->addLayout(buttonLayout);
    mainLayout->addSpacing(30);


    QHBoxLayout *closeLayout = new QHBoxLayout();
    closeLayout->addStretch();
    closeLayout->addWidget(closeButton);
    closeLayout->addStretch();

    mainLayout->addLayout(closeLayout);
    mainLayout->addStretch();

    setLayout(mainLayout);
}

void startwidget::setupConnections()
{
    connect(startButton, &QPushButton::clicked, this, &startwidget::onStartButtonClicked);
    connect(closeButton, &QPushButton::clicked, this, &startwidget::onCloseButtonClicked);
}

void startwidget::onStartButtonClicked()
{
    emit startGame();
}

void startwidget::onCloseButtonClicked()
{
    close();
}
